const EventEmitter = require('events');
const util = require('util');

function Radio(name, frequency) {
  EventEmitter.call(this);
  this.name = name;
  this.frequency = frequency;
}

util.inherits(Radio, EventEmitter);

Radio.prototype.play = function play() {
  this.emit('open', this.name, this.frequency);
  const self = this;
  setTimeout(function singing() {
    self.emit('playing', 'lalalala...');
  }, 2000);
};

Radio.prototype.stop = function stop() {
  this.emit('close', this.name, this.frequency);
};

module.exports = Radio;
